package com.hbnu.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void addUser(){
        //System.out.println("数据层添加用户");

        String sql = "insert into tb_user(name,password,addr,salary)values(?,?,?,?)";
        int row = jdbcTemplate.update(sql, "panpanh", "ph9908", "湖北黄冈", 10000.00);
        System.out.println(row==1 ? "数据添加成功" : "数据添加失败");
    }

    public void leesMoney(){
        String sql = "update tb_user set salary = salary - ? where name = ?";
        int row = jdbcTemplate.update(sql, 1000.00, "panpanh");
        System.out.println(row == 1 ? "panpanh转账成功" : "panpanh转账失败");
    }

    public void moreMoney(){
        String sql = "update tb_user set salary = salary + ? where name = ?";
        int row = jdbcTemplate.update(sql, 1000.00, "panhao");
        System.out.println(row == 1 ? "panhao收款成功" : "panhao收款失败");
    }
}
